


/**
	Author		: Rohan
	Date		: April 22nd 2004
	Description	: This method will update the shipping address of all the sales orders
		          which are not yet shipped.
*/


ALTER proc sp_update_gp_customer_default_shippindAddress
@customer_id int, 
@address_id int

AS

BEGIN

	declare @sales_order_id int
	declare @present_address_id int
	declare @update_address_cursor CURSOR
	
	/*
	 * Update the ShippingAddress Id for all the Sales_orders not Shipped
	 */

	set @update_address_cursor = CURSOR FOR
	SELECT DISTINCT SalesOrder_ID from fn_load_view_orders ('0','0',1,'BACKLOG')

	open @update_address_cursor		
		fetch next from @update_address_cursor into @sales_order_id
	
		while @@fetch_status = 0
		begin		

			UPDATE Sales_Order SET SO_Shipping_Address_ID = @address_id
				WHERE SalesOrder_ID = @sales_order_id and 
				Customer_ID = @customer_id

			fetch next from @update_address_cursor into @sales_order_id
		end
			
		close @update_address_cursor
		deallocate @update_address_cursor

END


